home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
bplus25a.zip
/
VTEST.C
< prev
Wrap
Text File
|
1990-12-30
|
3KB
|
108 lines
/* VTEST.C test program. */
/* This is a simple test program which creates two index files. */
/* 100 keys are added to each file, some keys are deleted and */
/* then the keys are added back to the file. The keys are listed */
/* in ascending and decending order. */
#include "bplus.h"
#include <stdio.h>
#include <time.h>
#include <conio.h>
IX_DESC name1, name2; /* index file variables */
/* function prototypes */
void uplist (IX_DESC *);
void downlist (IX_DESC *);
void uplist(name) /* list keys in ascending order */
IX_DESC *name;
{
ENTRY ee;
if (first_key(&ee, name)) printf("%s ", ee.key);
while (next_key(&ee, name) == IX_OK) printf("%s ",ee.key);
printf("\nPress any key to continue \n");
getch();
}
void downlist(name) /* list keys in decending order */
IX_DESC *name;
{
ENTRY ee;
if (last_key(&ee, name)) printf("%s ", ee.key);
while (prev_key(&ee, name) == IX_OK) printf("%s ",ee.key);
printf("\nPress any key to continue \n");
getch();
}
void main()
{
int i;
clock_t clock(void);
float stime, etime;
ENTRY e;
printf("Make two index files\n");
make_index("test1.idx",&name1, 0);
make_index("test2.idx",&name2, 1);
printf("Indexing 100 items in two index files:\n");
/* note the time to index */
stime = (float) clock();
/* add 100 keys to each index file */
for (i = 0; i < 100; i++)
{
e.recptr = (long) i;
sprintf(e.key, "VALUE1-%2d",i);
add_key(&e, &name1);
sprintf(e.key, "VALUE2-%2d",i);
add_key(&e, &name2);
}
/* print the time required for indexing the two files */
etime = (float) clock();
printf("Indexing is complete. The time was %f\n\n", (etime - stime)/CLK_TCK);
printf("List the keys in each index file in ascending order:\n\n");
uplist(&name1);
uplist(&name2);
/* delete some keys and list again */
printf("\nNow delete all keys from 20 to 90 in each file\n\n");
for (i = 20; i < 90; i++)
{
e.recptr = (long) i;
sprintf(e.key, "VALUE1-%2d",i);
delete_key(&e, &name1);
sprintf(e.key, "VALUE2-%2d",i);
delete_key(&e, &name2);
}
printf("List the keys now for each index file in ascending order:\n\n");
uplist(&name1);
uplist(&name2);
/* add the keys back and list again */
printf("Now add back all items from 20 to 90 to each index\n\n");
for (i = 20; i < 90; i++)
{
e.recptr = (long) i;
sprintf(e.key, "VALUE1-%d",i);
add_key(&e, &name1);
sprintf(e.key, "VALUE2-%d",i);
add_key(&e, &name2);
}
printf("List the keys for each index file again in ascending order:\n\n");
uplist(&name1);
uplist(&name2);
/* list both files in decending order */
printf("List the keys for each index file in decending order\n\n");
downlist(&name1);
downlist(&name2);
/* always close all files */
close_index(&name1);
close_index(&name2);
}